import { AntdBaseTable } from '@/base/TBaseTable';
import styles from './index.less';

const BaseTable = (props: any) => {
  const { tableData, tableHeader = [], fixed, nSixFixed, hasStickyScroll } = props;
  // 处理表头
  const getColumns = (columsValue: any[]) => {
    const columns: any[] = [];
    columns.push({
      name: '类型',
      align: 'left',
      code: 'title',
      width: 120,
      lock: true,
    });
    columsValue.map((t) => {
      columns.push({
        name: t.name,
        align: 'center',
        code: t.field,
        width: fixed || nSixFixed ? 80 : 60,
        render: (value: any) => {
          if (value === null || value === '-') {
            return '-';
          }
          return fixed ? parseFloat(value).toFixed(3) : Math.round(value * 100) / 100;
        },
      });
    });
    return columns;
  };
  return (
    <div className={styles.outside}>
      <AntdBaseTable
        className={['bordered', `${styles.custor}`].join(' ')}
        style={{
          // '--header-bgcolor': '#383C3E',
          // '--header-color': 'white',
          '--row-height': '28px',
          '--header-row-height': '30px',
          // '--bgcolor': '#222629',
          // '--color': '#D3D4D4',
          '--cell-padding': '0px 8px',
        }}
        // useVirtual={{ vertical: true, header: false }}
        dataSource={tableData}
        columns={getColumns(tableHeader)}
        defaultColumnWidth={81}
        useOuterBorder={true}
        hasStickyScroll={hasStickyScroll}
      />
    </div>
  );
};

export default BaseTable;
